package io.adrainty.bolee.insurance.web;

import io.adrainty.bolee.framework.commons.basic.EnableEnum;
import io.adrainty.bolee.framework.commons.basic.ResultDTO;
import io.adrainty.bolee.framework.commons.basic.TreeDTO;
import io.adrainty.bolee.framework.commons.utils.ResultDTOUtil;
import io.adrainty.bolee.insurance.models.entity.CategoryConditionEntity;
import io.adrainty.bolee.insurance.models.entity.CategoryEntity;
import io.adrainty.bolee.insurance.models.entity.InsuranceEntity;
import io.adrainty.bolee.insurance.service.ICategoryService;
import io.adrainty.bolee.insurance.service.IInsuranceService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>ProductController</p>
 *
 * @author AdRainty
 * @version V1.0.0
 * @description ProductController
 * @since 2025/8/22 14:37:54
 */

@Tag(name = "产品管理")
@RestController
@RequestMapping("/product")
public class ProductController {

    @Resource
    private ICategoryService categoryService;

    @Resource
    private IInsuranceService insuranceService;

    @Operation(summary = "查询产品分类树")
    @PostMapping("/find-product-categorys")
    public ResultDTO<TreeDTO> findProductCategories(CategoryEntity categoryEntity) {
        TreeDTO treeDTO = categoryService.categoryTree(categoryEntity);
        return ResultDTOUtil.success(treeDTO);
    }

    @Operation(summary = "查询产品分类下筛选项目")
    @PostMapping("/find-condition/{categoryNo}")
    public ResultDTO<List<CategoryConditionEntity>> findCategoryCondition(@PathVariable("categoryNo") String categoryNo) {
        CategoryConditionEntity entity = CategoryConditionEntity.builder()
                .categoryNo(categoryNo)
                .dataState(EnableEnum.ENABLE)
                .build();
        List<CategoryConditionEntity> categoryConditionEntities =
                categoryService.findCategoryConditionList(entity);
        return ResultDTOUtil.success(categoryConditionEntities);
    }

    @Operation(summary = "查询保险产品")
    @PostMapping("/find-insurance-product")
    public ResultDTO<List<InsuranceEntity>> findInsuranceProduct(@RequestBody InsuranceEntity insuranceEntity) {
        insuranceEntity.setDataState(EnableEnum.ENABLE);
        List<InsuranceEntity> insuranceEntities = insuranceService.listInsurance(insuranceEntity);
        return ResultDTOUtil.success(insuranceEntities);
    }

    @Operation(summary = "保险产品详情")
    @PostMapping("/find-insurance/{insuranceId}")
    public ResultDTO<InsuranceEntity> findInsuranceDetails(@PathVariable("insuranceId") Long insuranceId) {
        InsuranceEntity insuranceEntity = insuranceService.findInsuranceDetails(insuranceId);
        return ResultDTOUtil.success(insuranceEntity);
    }

}
